<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title><{:C('web_site_name')}>---广告编辑</title>
<link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/common.css"/>
<link rel="stylesheet" type="text/css" href="<?php echo APP_TMPL_PATH ; ?>/static/css/main.css"/>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/lib.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/layer/layer.min.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/fileuploader.js"></script>
<script type="text/javascript" src="<?php echo APP_TMPL_PATH ; ?>/static/js/DatePicker/WdatePicker.js"></script>

</head>
<body>


<form  id="info_form" >
<input type="hidden" value="<?php echo isset($id)?$id:0 ;?>" name="info[id]">
<div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>首页<span class="crumb-step">&gt;</span><span class="crumb-name">广告编辑</span></div>
        </div>
        
        <div class="result-wrap">
            <div class="result-content">
                    <table class="insert-tab" width="100%">
                        <tbody>
                            
                            <tr>
                                <th><i class="require-red">*</i>广告名称：</th>
                                <td>
                                <input id="title" name="info[name]" type="text" value="<?php echo $info['name'];?>" class="common-text required" />
           
                                </td>
                            </tr>
                             <tr>
                                <th><i class="require-red">*</i>广告类别</th>
                                <td>
                               <select name="info[ad_type]" class="select2" id="ad_type">
                    <?php 
                   
                        if(isset($ad_type) && $ad_type){
                            foreach($ad_type as $gkey_ => $gval_){  
                        
                    ?>
                <option value="<?php echo $gval_['id'] ;?>" <?php if($info['ad_type'] == $gval_['id']  ){echo "selected";}?>><?php echo $gval_['typename'] ;?></option>
                <?php 
                    }
                }   
        ?>
        </select>
           
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red"></i>广告类型：</th>
                                <td>
                                <select name="info[type]"  class="select2" onchange="_ad()" id="type">
                                <option value="0" <?php if($info['type'] == 0  ){echo "selected";}?>>图片广告</option>
                                <option value="1" <?php if($info['type'] == 1  ){echo "selected";}?>>文字广告</option>
                                
                                </select>
                            
                                </td>
                            </tr> 
                            <tbody id="t_0" class="pp" <?php if($info['type'] == '1'  ){echo "style='display:none'";}?>>
                            
                             <tr>
                                <th><i class="require-red"></i>图片1：</th>
                                <td>
                                <input type="text" value="<?php echo $info['pic'];?>" name="info[pic]" id="pc_image" readonly><a id="upload_pic" href="javascript:void(0)" class="btn btn-primary btn2">上传图片</a>
                            
                                </td>
                            </tr> 
                            <tr>
                                <th><i class="require-red"></i>图片预览：</th>
                                <td>
                                <img id="pc_preview" src="<?php echo C('upload_domain')?>/Ad/<?php echo $info['pic'];?>" width='80' height='80' style="display:">
                            
                                </td>
                            </tr> 
                            <tr>
                                <th><i class="require-red"></i>图片2：</th>
                                <td>
                                <input type="text" value="<?php echo $info['pic2'];?>" name="info[pic2]" id="pic2"  readonly><a id="upload_pic2" href="javascript:void(0)" class="btn btn-primary btn2">上传图片</a>
                            
                                </td>
                            </tr> 
                            <tr>
                                <th><i class="require-red"></i>图片预览：</th>
                                <td>
                                <img id="pic2_preview" src="<?php echo C('upload_domain')?>/Ad/<?php echo $info['pic2'];?>" width='80' height='80' style="display:">
                            
                                </td>
                            </tr> 

                            <tr>
                                <th>图片描述：</th>
                                <td>
                                <input id="title"  value="<?php echo $info['pic_des'];?>" name="info[pic_des]" type="text" value="" class="common-text required" />
           
                                </td>
                            </tr>
                            <tr>
                                <th>广告链接地址</th>
                                <td>
                                <input id="pic_url" name="info[pic_url]" type="text" value="<?php echo $info['pic_url'];?>" class="common-text required" />
                              <i>广告的跳转地址：例如:http://www.speakphp.com</i>
                                </td>
                            </tr>
                             </tbody>
                         
                            <tbody id="t_1" class="pp" style="display:none">
                            <tr> 
                                <th>文字描述</th>
                                <td>
                                <input id="words" value="<?php echo $info['words'];?>" name="info[words]" type="text"  class="common-text required" />
                                 
                                </td>
                            </tr>
                            </tbody>
                            <tr> 
                                <th>属性1</th>
                                <td>
                                <input id="attr_1" name="info[attr_1]" type="text" value="<?php echo $info['attr_1'];?>" class="common-text required" />
                             <i>广告属性1</i>
                                </td>
                            </tr> 
                           <tr> 
                                <th>属性2</th>
                                <td>
                                <input id="attr_2" name="info[attr_2]" type="text" value="<?php echo $info['attr_2'];?>" class="common-text required" /><i>广告属性2</i>
           
                                </td>
                            </tr> 
                             <tr> 
                                <th>开始日期：</th>
                                <td>
                                <input name='info[begin_date]' onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"  id="begin_date" type="text" readonly class="common-text required" value="<?php echo ($info['begin_date'] > 0 )?date("Y-m-d H:i:s" , $info['begin_date']):0;?>"/><i>如果不选永不过期</i>
           
                                </td>
                            </tr>
                            <tr> 
                                <th>结束日期：</th>
                                <td>
                                <input name='info[end_date]' onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"  id="end_date" type="text" readonly class="common-text required" value="<?php echo ($info['end_date'] > 0 )?date("Y-m-d H:i:s" , $info['end_date']):0;?>" />
                              <i>如果不选永不过期</i>
                                </td>
                            </tr>
                          
                         <tr> 
                                <th>权重</th>
                                <td>
                                <input id="weight" name="info[weight]" type="text" value="<?php echo $info['weight'];?>" class="common-text required" />
                                 
                                </td>
                            </tr>
                        
                            <tr>
                                <th>状态：</th>
                                <td>
                                <input type="radio" name="info[status]" value="1" <?php if($info['status'] == 1 ){echo "checked";}?>/> 启用
                                 <input type="radio" name="info[status]" value="0" <?php if($info['status'] == 0 ){echo "checked";}?>/> 禁用
                                </td>
                            </tr>
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" id="btn" value="提交" type="button">
                                </td>
                            </tr>
                        </tbody></table>
            </div>
        </div>
       
      </form>  
    
   </body>
   </html>    
   
<script>

var loadding_0 ;
$(function(){
    $("#btn").bind("click" , function(){
        if($.trim($("#title").val()) == '' ){
            layer.msg("名称不可以为空");
            return false ;
        }
        var data_ = $("#info_form").serializeArray() ;
        $.ajax({
            type: "POST",
            url: "<?php echo  U("ad/edit" , array('action'=>'doedit' , 'inajax'=>1 ) ) ; ?>" ,
            data: data_,
            cache:false,
            dataType:"json",
            async:true,
            success: function(msg){
                var shtml = '' ;
                var list = msg.resultinfo.list;
                if(msg.resultcode != 1 ){
                    layer.msg(msg.resultinfo.errmsg);
                    return false ;
                }else{
                    parent.common_request();
                    parent.close_edit_div();
                }
                layer.close(loadding_0);
            },
            beforeSend:function(){
                 loadding_0 = layer.load('数据正在加载中。。。。。。'); 
            },
            error:function(){
                layer.msg('服务器繁忙请稍后');
                return false ;
            }
            });
        
    });
     var img_uploader = new qq.FileUploaderBasic({
            allowedExtensions: ['jpg','gif','jpeg','png'],
            button: document.getElementById("upload_pic"),
            multiple: false,
            action: "<?php echo U('Ad/index' , array('action'=>'upload_pic') )?>",
            inputName: 'file',
            forceMultipart: true, //用$_FILES
            messages: {
                typeError: "图片类型出错",
                //sizeError: "七个上传小图",
                //minSizeError: lang.upload_minsize_error,
                //emptyError: lang.upload_empty_error,
                noFilesError: "没有文件上传"
                //onLeave: lang.upload_onLeave
            },
            showMessage: function(message){
               alert(message);
            },
            onSubmit: function(id, fileName){
                loadding_0 = layer.load('图片正在上传中，请稍等。。。。'); 
            },
            onComplete: function(id, fileName, result){
                
                if(result['resultcode']){
                    $("#pc_image").val(result['resultinfo']['list']['pic']);
                    $("#pc_preview").attr("src" , "<?php echo C('upload_domain')?>/Ad/"+result['resultinfo']['list']['pic']).show();
                }else{
                    layer.msg(result['message']);
                }
                layer.close(loadding_0);
            }
        }); 
     var pc_img_uploader = new qq.FileUploaderBasic({
            allowedExtensions: ['jpg','gif','jpeg','png'],
            button: document.getElementById("upload_pic2"),
            multiple: false,
            action: "<?php echo U('ad/index' , array('action'=>'upload_pic') )?>",
            inputName: 'file_pc',
            forceMultipart: true, //用$_FILES
            messages: {
                typeError: "图片类型出错",
                //sizeError: "七个上传小图",
                //minSizeError: lang.upload_minsize_error,
                //emptyError: lang.upload_empty_error,
                noFilesError: "没有文件上传"
                //onLeave: lang.upload_onLeave
            },
            showMessage: function(message){
               alert(message);
            },
            onSubmit: function(id, fileName){
                loadding_0 = layer.load('图片正在上传中，请稍等。。。。'); 
            },
            onComplete: function(id, fileName, result){
                
                if(result['resultcode']){
                    $("#pic2").val(result['resultinfo']['list']['pic']);
                    $("#pic2_preview").attr("src" , "<?php echo C('upload_domain')?>/Ad/"+result['resultinfo']['list']['pic']).show();
                }else{
                    layer.msg(result['message']);
                }
                layer.close(loadding_0);
            }
        }); 
             
}) ; 

function _ad(){
        $(".pp").hide() ; 
        $("#t_"+$("#type").val()).show() ; 
    }
</script>
        
        